package com.tongren.framework.sample;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.tongren.framework.R;
import com.tongren.framework.constants.ConstantValues;
import com.tongren.framework.core.AppStatusTracker;
import com.tongren.framework.core.BaseActivity;
import com.tongren.framework.core.CustomApplication;
import com.tongren.framework.me.activity.LoginActivity;
import com.tongren.framework.model.BaseUser;

/**
 * Powered by
 */
public class WelcomeActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        AppStatusTracker.getInstance().setAppStatus(ConstantValues.STATUS_OFFLINE);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setUpContentView() {
        setContentView(R.layout.activity_welcome, -1, MODE_NONE);
    }

    @Override
    protected void setUpView() {

    }

    @Override
    protected void setUpData(Bundle savedInstanceState) {
        handler.sendEmptyMessageDelayed(0, 2000);
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            LoginActivity();
        }
    };

    @Override
    protected void onPause() {
        super.onPause();
        handler.removeMessages(0);
    }

    private void LoginActivity() {

            BaseUser user = CustomApplication.getInstance().getUserModel();
            if (user != null) {

                startActivity(new Intent(WelcomeActivity.this, SampleTabActivity.class));
                finish();
                //LoadingActivity.this.finish();
            } else {
                Intent it = new Intent(WelcomeActivity.this, LoginActivity.class);
                startActivity(it);
                WelcomeActivity.this.finish();

            }

    }

}
